<template>
  <a-drawer :title="title" width="40%" :visible="visible" :confirmLoading="loading" @close="() => {
      this.visible = false
    }
    ">
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity"  v-bind="layout">
        <a-form-model-item label="业务仓库ID" prop="BusStoreId" >
          <a-input v-model="entity.BusStoreId" autocomplete="off" placeholder="业务仓库ID" />
        </a-form-model-item>
        <a-form-model-item label="财务仓库ID" prop="FinStoreId">
          <a-input v-model="entity.FinStoreId" autocomplete="off" placeholder="财务仓库ID" />
        </a-form-model-item>
        <a-form-model-item label="业务仓库" prop="BusStoreName">
          <a-input v-model="entity.BusStoreName" autocomplete="off" placeholder="业务仓库" />
        </a-form-model-item>
        <a-form-model-item label="财务仓库" prop="FinStoreName">
          <a-input v-model="entity.FinStoreName" autocomplete="off" placeholder="财务仓库" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
    <div :style="{
      position: 'absolute',
      right: 0,
      bottom: 0,
      width: '100%',
      borderTop: '1px solid #e9e9e9',
      padding: '4px 16px',
      background: '#fff',
      textAlign: 'right',
      zIndex: 1
    }">
      <a-button type="primary" @click="handleSave">确定</a-button>&nbsp;
      <a-button @click="close">取消</a-button>&nbsp;
    </div>
  </a-drawer>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      title: ''
    }
  },
  methods: {
    handleSave() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$http.post('/Cfg/cfg_compare_store/SaveData', this.entity).then(res => {
            if (res.Success) {
              this.$message.success('保存成功!')
              this.visible = false
              this.parentObj.getDataList();
            }
          }).catch(err => {
            this.$message.error(err)
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      })
      
    },
    close() {
      this.visible = false
      this.entity = {}
    },
    init() {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title) {
      this.init()
      this.title = title
      if (id) {
        this.loading = true
        this.$http.post('/Cfg/cfg_compare_store/GetTheData', { id: id }).then(resJson => {
          this.loading = false
          this.entity = resJson.Data
        })
      }
    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/OrderManagement/Ap_CloseBill/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
